package com.puboot.module.blog.controller;

import com.puboot.common.util.UUIDUtil;
import com.puboot.module.admin.service.BizThemeService;
import com.puboot.module.admin.service.RedisService;
import com.puboot.module.blog.model.Agreement;
import com.puboot.module.blog.service.CustomerService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.TimeUnit;

import static com.puboot.common.util.CoreConst.THEME_PREFIX;

@Controller
@AllArgsConstructor
public class RegistController {
    private BizThemeService bizThemeService;
    private RedisService redisService;
    private CustomerService customerService;

    @RequestMapping("/blog/regist")
    public String registIndex(Model model) {
        //静态化，注册页面暂时不需要
     /*   if (CoreConst.SITE_STATIC.get()) {
            return "forward:/html/comment/regist.html";
        }*/
        model.addAttribute("categoryId", "regist");
        String pagecode = UUIDUtil.uuid();
        redisService.set(pagecode, pagecode, 30, TimeUnit.MINUTES);
        model.addAttribute("pagecode", pagecode);
        //return THEME_PREFIX + bizThemeService.selectCurrent().getName() + "/regist";
        return THEME_PREFIX + "cweb" + "/regist";
    }

    /**
     * 登录
     *
     * @param model
     * @return
     */
    @RequestMapping("/blog/login")
    public String loginIndex(Model model) {
        //静态化，注册页面暂时不需要
     /*   if (CoreConst.SITE_STATIC.get()) {
            return "forward:/html/comment/login.html";
        }*/
        //return THEME_PREFIX + bizThemeService.selectCurrent().getName() + "/login";
        return THEME_PREFIX + "cweb" + "/login";
    }


    /**
     * 忘记密码
     *
     * @param model
     * @return
     */
    @RequestMapping("/blog/forget")
    public String forget(Model model) {
        //静态化，注册页面暂时不需要
     /*   if (CoreConst.SITE_STATIC.get()) {
            return "forward:/html/comment/login.html";
        }*/
        //return THEME_PREFIX + bizThemeService.selectCurrent().getName() + "/login";
        return THEME_PREFIX + "cweb" + "/forget";
    }

    /**
     * 注册协议
     *
     * @param model
     * @return
     */
    @RequestMapping("/blog/agreement")
    public String agreement(Model model) {
     /*   if (CoreConst.SITE_STATIC.get()) {
            return "forward:/html/comment/login.html";
        }*/
        //return THEME_PREFIX + bizThemeService.selectCurrent().getName() + "/login";
        Agreement agreement = customerService.getAgreement();
        model.addAttribute("agreement", agreement);
        return THEME_PREFIX + "cweb" + "/agreement";
    }
}
